package com.cl.code.generate.module.typescript.strategy;

import com.cl.code.generate.common.strategy.GenerationStrategy;
import com.cl.code.generate.source.controller.entity.ControllerMetadata;
import lombok.Getter;

import java.io.File;
import java.util.HashMap;
import java.util.Map;

/**
 * @author chengliang
 * @since 1.0.0
 */
public class TypeScriptFileGenerationStrategy implements GenerationStrategy {

    @Getter
    private final String templatePath;

    @Getter
    private String fileExtension = ".ts";

    @Getter
    private final String outputDir;

    private final String fileName;

    @Getter
    private final Class<?> controllerClass;

    public TypeScriptFileGenerationStrategy(String templatePath, String outputDir, String fileName, Class<?> controllerClass) {
        this.templatePath = templatePath;
        this.outputDir = outputDir;
        this.fileName = fileName;
        this.controllerClass = controllerClass;
    }

    @Override
    public String getOutputPath() {
        return File.separator + outputDir;
    }

    /**
     * 构建模板数据模型
     *
     * @return 模板数据模型
     */
    public Map<String, Object> buildDataModel(ControllerMetadata controllerMetadata) {
        // 创建基础数据模型
        Map<String, Object> dataModel = new HashMap<>();

        dataModel.put("fileName", fileName);
        dataModel.put("basePath", controllerMetadata.getBasePath());
        dataModel.put("comment", controllerMetadata.getComment());
        dataModel.put("author", controllerMetadata.getAuthor());
        dataModel.put("methods", controllerMetadata.getMethods());

        return dataModel;
    }

}
